home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / pc / RGASM.RAR / ASMCODE.EXE / CHAPT11 / FSECRET.ASM < prev    next >
Encoding:
Assembly Source File  |  1993-05-10  |  14.7 KB  |  270 lines

  1. ;       Program FSecret ( Chapter 11 )
  2. ;
  3.     page    55,132
  4. ;
  5. ;       This program installs additional handlers for interrupt 13h
  6. ;
  7. ;       New function 0EFh of interrupt 13h has been added.
  8. ;       This function has 3 subfunctions:
  9. ;       00 - installation check
  10. ;       01 - activates the driver
  11. ;       02 - deactivates the driver
  12. ;       03 - report the driver state; returns the state in AH (1 - on, 2 - off)  
  13. ;       To call new function put its number into the AH register, 
  14. ;       the subfunction number into AL and call interrupt 13h
  15. ;
  16. NewFunc equ     0E0h
  17. CheckIn equ     0                       ; subfunction "check installation"
  18. IdSwOn  equ     1                       ; subfunction "turn program on"
  19. IdSwOff equ     2                       ; subfunction "turn program off"
  20. RepSt   equ     3                       ; subfunction "report status"
  21. IdUnIn  equ     4                       ; subfunction "get resident PSP address"
  22. InAct   equ     0                       ; this value indicates "INACTIVE"
  23. Act     equ     13h                     ; this value indicates "ACTIVE"
  24.  
  25. _Text   segment para public 'CODE'
  26.     assume  cs:_Text
  27. ;====================  Resident data =====================================      
  28. ActInd  db      Act                     ; activity indicator; if 0 - inactive
  29. ResPSP  dw      ?                       ; addres of resident PSP
  30. ResOff  dw      ?                       ; offset of resident part
  31. ResSeg  dw      ?                       ; segment of resident part
  32. ;=====================  Resident code ====================================
  33. Handler proc    near                    ; additional handler for interrupt 13h
  34.     pushf
  35.     cmp     ah,NewFunc              ; additional function of INT 13h?
  36.     je      Addf                    ; new handler for that function
  37.     cmp     ActInd,Act              ; is activity indicator set?
  38.     jne     ToOld13                 ; if so, continue work
  39. ;===    Check whether the screen is already blanked
  40. Process:cmp     dl,79h                  ; Is the floppy disk requested?
  41.     ja      ToOld13                 ; If not, jump to the old handler
  42.     cmp     ah,03h                  ; Function 03 - write sector
  43.     je      RepCod                  ;    new handler for function 03
  44.     cmp     ah,0Bh                  ; Function 0B - write long sector
  45.     je      RepCod                  ;    new handler for function 0Bh
  46.     jmp     ToOld13                 ; Others processed by old handler
  47. ;===    Process write commands
  48. RepCod: cmp     ActInd,Act              ; Is the active mode set?
  49.     jne     ToOld13                 ; If not, jump to the olf handler
  50.     mov     ah,04h                  ; Function 04h - verify sector
  51. ;===    Pass the control to the standard handler of the interrupt 13h   
  52. ToOld13:popf
  53.     db      0EAh                    ; this is code for JMP FAR
  54. OldOff  dw      0                       ; here will be ofsset
  55. OldSeg  dw      0                       ; here will be segment
  56. ;===    Process additional function of interrupt 13h
  57. Addf:   cmp     al,CheckIn              ; is installation check required?
  58.     je      Inst
  59.     cmp     al,IdSwOn               ; turn driver ON?
  60.     je      SwOn
  61.     cmp     al,IdSwOff              ; turn driver OFF?
  62.     je      SwOff
  63.     cmp     al,RepSt                ; report status?
  64.     je      Report
  65.     cmp     al,IdUnIn
  66.     je      RetPSP
  67.     jmp     ToOld13                 ; unknown command - pass to old handler
  68. Inst:   mov     ah,CheckIn              ; value to be returned into AH
  69.     jmp     ExHand                  ; exit handler
  70. SwOn:   mov     ActInd,Act              ; set indicator to ACTIVE (ON)
  71.     mov     ah,IdSwOn               ; value to be returned into AH
  72.     jmp     ExHand                  ; exit handler
  73. SwOff:  mov     ActInd,InACt            ; set indicator to INACTIVE (OFF)
  74.     mov     ah,IdSwOff              ; value to be returned into AH
  75.     jmp     ExHand                  ; exit handler
  76. RetPSP: mov     ah,IdUnIn               ; value to be returned into AX
  77.     mov     dx,ResPsp
  78.     mov     es:[bx+0],dx            ; segment address of resident PSP
  79.     mov     dx,OldOff
  80.     mov     es:[bx+2],dx            ; offset addres of old handler
  81.     mov     dx,OldSeg
  82.     mov     es:[bx+4],dx            ; segment address of old handler
  83.     mov     dx,Resoff
  84.     mov     es:[bx+6],dx            ; offset addres of this handler
  85.     mov     dx,ResSeg
  86.     mov     es:[bx+8],dx            ; segment address of this handler
  87.     jmp     ExHand                  ; exit handler
  88. Report: mov     ah,IdSwOff              ; prepare "InActive" code for returning
  89.     cmp     ActInd,Act              ; is activity indicator set?
  90.     jne     ExHand                  ; if not, exit handler
  91.     mov     ah,IdSwOn               ; return "Active" code
  92. ExHand: mov     al,NewFunc              ; return additional signature in AL
  93.     popf
  94.     iret                            ; return from handler   
  95. Handler endp
  96. ;===    Installation part of the program
  97. BegInst label   byte
  98. ParmInd db      0
  99. PspAddr dw      ?
  100. ComSeg  dw      ?
  101. ResArea dw      5 dup (?)               ; buufer for subfunction "return PSP"
  102. RetCode db      0
  103. Start:  mov     PspAddr,es              ; save address of PSP
  104.     mov     sp,0F000h               ; set the stack
  105. ;===    Free the environment memory block
  106.     mov     es,es:[2Ch]             ; address of environment block into ES 
  107.     mov     ah,49h                  ; function 49h - free memory block
  108.     int     21h                     ; DOS service call
  109. ;===
  110.     mov     es,PspAddr              ; set ES to point to PSP
  111.     mov     ComSeg,cs               ; save current command segment
  112.     mov     ds,ComSeg               ; DS = CS - data and code are the same 
  113. ;===    check whether the program is alrady installed
  114.     mov     ah,NewFunc              ; new funtion of INT 13h
  115.     mov     al,CheckIn              ; AL - installation check
  116.     int     13h                     ; call interrupt 13h - timer tick
  117.     cmp     ah,Checkin              ; does AH contain function number?
  118.     je      Already                 ; if YES, handler is already installed
  119. ;===    output the initial message
  120.     mov     ah,09                   ; function 09 - text string output
  121.     lea     dx,BegMsg               ; DX - address of message
  122.     int     21h                     ; DOS service call
  123.     mov     ResPSP,es               ; save PSP of resident part
  124. ;===    modyfying IVT   
  125.     mov     ax,3513h                ; function 35h - Get Interrupt Vector
  126.     int     21h                     ; DOS service call
  127.     mov     OldOff,bx               ; save offsett of old handler for 13h
  128.     mov     OldSeg,es               ; save segment of old handler for 13h
  129.     mov     ResOff,offset Handler   ; save offset of resident part
  130.     mov     ResSeg,ds               ; save segment odf resident part
  131.     cli                             ; caution! critical part of program
  132.     mov     dx,ResOff               ; address of handler
  133.     mov     ax,2513h                ; function 25h - Set new handler
  134.     int     21h                     ; DOS service call
  135.     sti                             ; critical part finishes here
  136. ;===    output the message "program is installed"
  137.     mov     ActInd,Act              ; set activity indicator (TSR "ON")
  138.     lea     dx,Loaded               ; DX - address of message
  139.     mov     ah,09h                  ; function 09 - output string
  140.     int     21h                     ; DOS service call
  141. ;===    calculate the size of the resident part 
  142.     lea     dx,BegInst              ; address of installation part beginning
  143.     add     dx,110h                 ; PSP length plus 16 byte (insurance) 
  144.     mov     cx,4                    ; set counter for shift
  145.     shr     dx,cl                   ; 4 bits to the right - divide by 16
  146.     mov     ax,3100h                ; 31h - terminate and state resident
  147.     int     21h                     ; DOS service call
  148. ;===    Normal exit from program (return code 0)
  149. NormEx: mov     ds,ComSeg               ; restore DS (can be destroyed)
  150.     mov     ah,09h                  ; function 09 - output string
  151.     int     21h                     ; DOS service call
  152.     mov     ah,4Ch                  ; function 4Ch - terminate process
  153.     mov     RetCode,al              ; return code into AL
  154.     int     21h                     ; DOS service call
  155. ;===    Process situation "Resident part is already installed"
  156. Already:mov     es,PspAddr              ; addres of PSP into ES
  157.     cmp     byte ptr es:[80h],1     ; are there parameters? 
  158.     jle     NoParm                  ; if not, set the indicator "NoParm"
  159.     mov     bx,82h                  ; BX - beginning of parameter string
  160.     cmp     byte ptr es:[bx],'/'
  161.     jne     CheckS
  162. SkipSep:inc     bx
  163.     jmp     ChkLtr
  164. CheckS: cmp     byte ptr es:[bx],'-'
  165.     je      SkipSep
  166. ChkLtr: cmp     byte ptr es:[bx],'?'
  167.     je      Help
  168.     and     byte ptr es:[bx],0DFh   ; force first letter uppercase
  169.     cmp     byte ptr es:[bx],'H'    ; is first letter 'H'?
  170.     je      Help                    ; if so, process "HELP" 
  171.     cmp     byte ptr es:[bx],'U'    ; is first letter 'U'?
  172.     je      UnInst                  ; if so, process "UNINSTALL"    
  173.     cmp     byte ptr es:[bx],'O'    ; is first letter 'O'?
  174.     jne     InvParm                 ; if not - missing or invalid
  175.     and     byte ptr es:[bx+1],0DFh ; force second letter uppercase
  176.     cmp     byte ptr es:[bx+1],'N'  ; is second letter 'N'?
  177.     je      TurnOn                  ; if so, process "ON"
  178.     cmp     byte ptr es:[bx+1],'F'  ; is second letter 'F'?
  179.     jne     InvParm                 ; if not - invalid parameter
  180.     and     byte ptr es:[bx+2],0DFh ; force third letter uppercase
  181.     cmp     byte ptr es:[bx+2],'F'  ; is third letter 'F'?
  182.     jne     InvParm                 ; if not, process "INVALID PARMS"
  183.     mov     al,IdSwOff              ; code for subfunction "OFF" into AL
  184.     jmp     Switch                  ; switch program state
  185. ;===    deinstall new handler   
  186. Uninst: mov     ah,NewFunc              ; AH - code for additional function
  187. ;---    get information about the resident part (PSP, segment, offset)
  188.     mov     al,IdUnIn               ; AL - subfunction "deinstallation"
  189.     mov     es,ComSeg               ; ES points to current segment
  190.     mov     bx,offset ResArea       ; ES:BX - buffer for subf. "Return PSP"
  191. ;---    get information about current handler of interrupt 13   
  192.     int     13h                     ; call new handler of interrupt 13h
  193.     mov     ax,3513h                ; function 35h - get interrupt vector 
  194.     int     21h                     ; DOS service call
  195. ;---    is the resident part of this program last handler of interrupt 13h?     
  196.     mov     ax,es                   ; AX - segment of current handler
  197.     cmp     ax,ResArea[8]           ; segment of resident part 
  198.     jne     Over                    ; if not equal - res. part overriden
  199.     cmp     bx,ResArea[6]           ; compare offsets
  200.     jne     Over                    ; if not equal - res. part overriden 
  201. ;---    free memory occupied be the resident part of TSR        
  202.     mov     es,ResArea[0]           ; address of resident PSP into ES
  203.     mov     ah,49h                  ; function 49h - free memory block
  204.     int     21h                     ; DOS service call
  205. ;---    make previous handler of interrupt 13 current 
  206.     mov     ds,ResArea[4]           ; DS - segment of old handler
  207.     mov     dx,ResArea[2]           ; dx - offset of old handler
  208.     mov     ax,2513h                ; function 25h - set interrupt vector
  209.     int     21h                     ; DOS service call
  210.     mov     ds,ComSeg               ; restore data segment register
  211. ;---    leave program
  212.     lea     dx,UnInMsg              ; DS:DX - point to message "uninstalled"
  213.     jmp     NormEx                  ; leave program
  214. ;---    process situation "TSR overriden"
  215. Over:   lea     dx,OverMsg              ; DS:DX - point to message "overriden"
  216.     jmp     NormEx                  ; leave program
  217. ;===    Turn the program ON
  218. TurnOn: mov     al,IdSwOn               ; subfunction "Turn ON"
  219. ;===    This block switches program state       
  220. Switch: mov     ah,NewFunc              ; AH - code for additional function 
  221.     int     13h                     ; call new handler of interrupt 13h
  222. ;===    Process the situation "no parameter"    
  223. NoParm: mov     ah,NewFunc              ; AH - code for additional function
  224.     mov     al,RepSt                ; AL - subfunction "Report Status"
  225.     int     13h                     ; call new handler of interrupt 13h     
  226.     lea     dx,MakeOff              ; DS:DX - addres of message "Turned OFF"
  227.     cmp     ah,IdSwOn               ; is code "Turned ON" returned? 
  228.     jne     FinTst                  ; if not, exit; "OFF" will be output
  229.     lea     dx,MakeOn               ; DS:DX - addres of message "Turned ON"
  230. FinTst: jmp     NormEx                  ; to print message and exit
  231. ;===    Output help message     
  232. Help:   lea     dx,BegMsg               ; DS:DX - address of initial message    
  233. Help2:  mov     ah,09h                  ; function 09 - output text string
  234.     int     21h                     ; DOS service call
  235.     lea     dx,ParmTxt              ; DS:DX - address of HELP message
  236.     jmp     NormEx                  ; to print message and exit
  237. ;===    Process the sitution "INVALID PARAMETERS"
  238. InvParm:lea     dx,Invalid              ; DS:DX addres of message "Invalid"
  239.     mov     RetCode,1               ; return code = 1
  240.     jmp     Help2                   ; to print message and exit
  241. ;===    Data for non-resident part of the program
  242. CR      equ     0Ah
  243. LF      equ     0Dh
  244. EndMsg  equ     24h 
  245. Invalid db      CR,LF,'Can not interprete parameters specified.'
  246.     db      CR,LF,'The valid form of command line is:',CR,LF,EndMsg
  247. BegMsg  db      CR,LF,'The floppy disk security system  version 2.5   29.07.92'
  248.     db      CR,LF,'Copyright (C) 1992 V.B.Maljugin,    Russia,    Voronezh'
  249. CRLF    db      CR,LF,EndMsg
  250. Loaded  db      CR,LF,'Program is installed successfully',CR,LF,EndMsg
  251. MakeOn  db      CR,LF,'The floppy disk guard is now ACTIVE',CR,LF,EndMsg
  252. MakeOff db      CR,LF,'The floppy disk guard is now INACTIVE',CR,LF,EndMsg
  253. HelpTxt db      CR,LF,CR,LF, 'Call: '
  254. ParmTxt db      CR,LF,'FSecret [on | off | u | /? | /h | -? | -h] ',CR,LF
  255.     db      CR,LF,'Parameters:                                           '
  256.     db      CR,LF,'on  - make the floppy disk guard active               '
  257.     db      CR,LF,'off - make the floppy disk guard inactive             '
  258.     db      CR,LF,'u   - uninstall the floppy disk guard; FSecret must be'
  259.     db      CR,LF,'      the last handler for interrupt 13h'
  260.     db      CR,LF,'rest of list - output this text.',CR,LF
  261.     db      CR,LF,'First call of the program always means installation.'
  262.     db      CR,LF,'Call this program without parameters to determine its '
  263.     db            'current state.', CR,LF,EndMsg
  264. OverMsg db      CR,LF,'Program FSecret is not last handler of interrupt 13h.'
  265.     db      CR,LF,'Deinstallation denied. Please deinstall program manually'
  266.     db      CR,LF,EndMsg
  267. UnInMsg db      CR,LF,'Program FSecret uninstalled.',EndMsg     
  268. _text   ends
  269.     end     Start
  270.